<html>
<head><meta charset="utf-8"><title>How to convert TokenStream to AST · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20convert.20TokenStream.20to.20AST.html">How to convert TokenStream to AST</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="183231472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20convert%20TokenStream%20to%20AST/near/183231472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Derek <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20convert.20TokenStream.20to.20AST.html#183231472">(Dec 12 2019 at 06:11)</a>:</h4>
<p>Hi, by using libsyntax, I got <br>
let stream = source_file_to_stream(...)<br>
for tokentree in stream.trees(). <br>
my question is how can I covert tokenStream or TokenTree into AST.  <br>
Could anyone give some hint? which API or file i should look?  thanks for you help!</p>



<a name="183235485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20convert%20TokenStream%20to%20AST/near/183235485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20convert.20TokenStream.20to.20AST.html#183235485">(Dec 12 2019 at 07:56)</a>:</h4>
<p>I suggest you use the <code>syn</code> crate, the compiler's parser is not really meant for external consumption</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>